<template>
  <div>
    <Title title="数据统计" />
    <el-divider />
    <el-form>
      <el-form-item label="请选择对应的考试：">
        <el-select v-model="value" placeholder="请选择" @change="handleChange">
          <el-option
            v-for="item in options"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <div class="graph fx bw" v-if="info.score.length">
        <div class="score cm">
          <TData
            :o="{
              name: '分数占比',
              data: info.score,
            }"
          />
        </div>
        <div class="error cm">
          <Strip :names="info.names" :data="info.values" />
        </div>
      </div>
    </el-form>

    <!-- 预览 -->
    <div class="options bw" v-if="info.subjects.length">
      <li class="item fx" v-for="(item, i) in info.subjects" :key="i">
        <PreviewSingleSubject :name="item.name" :data="item.options" :i="i" />
        <div class="right">
          <CycleOption
            :o="{
              name: item.name,
              a: item.A,
              b: item.B,
              c: item.C,
              d: item.D,
            }"
          />
        </div>
      </li>
    </div>
    <el-empty
      description="暂时还没数据哦"
      class="bw"
      v-if="!info.score.length"
    />
  </div>
</template>

<script>
// const o = {
//     score: [{count: 1, score: 50}],
//     error: [{id: '1', count: 1}],
//     subjects: [
//         {
//             name: '',
//             ans: '',
//             options: ['', '', '', ''],
//             A: 1,
//             B: 2,
//             C: 3,
//             D: 4
//         }
//     ]
// }
import Title from "@/components/common/Title";
import Strip from "@/components/echart/Strip";
import TData from "@/components/echart/TData";
import CycleOption from "@/components/echart/CycleOption";
import PreviewSingleSubject from "@/components/preview/PreviewSingleSubject";
import { getPaperName, getTchData } from "@/api/paper";
import { formatTchData } from "@/utils";
export default {
  data() {
    return {
      options: [],
      value: "",
      info: {
        score: [],
        names: [],
        values: [],
        subjects: [],
      },
    };
  },
  methods: {
    async handleChange(v) {
      const { id } = this.options.find((o) => o.value === v);
      this.getData(id);
    },
    async getData(id) {
      const { data } = await getTchData(id);
      console.log(data)
      this.info = formatTchData(data);
    },
  },
  components: {
    Title,
    TData,
    Strip,
    PreviewSingleSubject,
    CycleOption,
  },
  async created() {
    const res = await getPaperName();
    this.options = res.data;
    if (this.options.length) {
      this.getData(this.options[0].id);
      this.value = this.options[0].value;
    }
  },
};
</script>

<style lang="scss" scoped>
.cm {
  width: 400px;
}

.graph {
  padding: 10px;
  justify-content: space-between;
}

.options {
  padding: 10px;
  margin-top: 20px;
}

.item {
  justify-content: space-between;
  border-bottom: 1px dashed #eaeaea;
  padding-bottom: 10px;
  margin-top: 10px;
}

.right {
  width: 300px;
}
</style>></style>
